# @Version : 1.0
# @Author  : 刘宇
# @File    : 31_set_exercise.py
# @Time    : 2025/10/14 14:57

s_history = {'小明', "张三", '李四', "王五", 'Lily', "Bob"}
s_politic = {'小明', "小花", '小红', "二狗"}
s_english = {'小明', 'Lily', "Bob", "Davil", "李四"}
print(f"选课学生总共有 {len(s_history | s_politic | s_english)}人")

print(
    f"只选了一门学科(history)的学生数量{len(s_history - s_politic - s_english)}人和学生姓名{s_history - s_politic - s_english}")

# 求只选了一门学科的学生数量和学生姓名
"""
    思路如下：
    1.求出只选择了history的学生
    2.求出只选择了politic的学生
    3.求出只选择了english的学生
    4.然后求并集集合
"""

# 1.求出只选择了history的学生
s1 = s_history - s_politic - s_english

# 2.求出只选择了politic的学生
s2 = s_politic - s_english - s_history

# 3.求出只选择了english的学生
s3 = s_english - s_history - s_politic

print(f"只选了一门学科的学生数量{len(s1 | s2 | s3)}和学生的姓名{s1 | s2 | s3}")

print(f"选了三门学科的学生数量{len(s_history & s_politic & s_english)}和学生的姓名{s_history & s_politic & s_english}")
